package org.example;

import java.util.LinkedList;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-11-08
 * 17:16
 */
public class Test {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String s=sc.nextLine();
        LinkedList<Integer> list=new LinkedList<>();
        while(n!=0){
            String ss=sc.nextLine();
            String[] ss1=ss.split(" ");
            n--;
            if(ss1[0].equals("insert")){
                int i=Integer.parseInt(ss1[1]);
                list.addFirst(i);
                continue;
            }
            if(ss1[0].equals("delete")){
                int i=Integer.parseInt(ss1[1]);
                list.removeFirstOccurrence(i);
                continue;
            }
            if(ss1[0].equals("deleteFirst")){
                list.pollFirst();
                continue;
            }
            if(ss1[0].equals("deleteLast")){
                list.pollLast();
                continue;
            }
        }
        for (Integer tmp:list) {
            System.out.print(tmp+" ");
        }
    }
}
